<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
  <div region="center" style="padding:0px;border:0px">
  <t:datagrid name="dictGroupList" checkbox="false" fitColumns="true" title="实验室开放设置" actionUrl="labOpenController.do?datagrid" idField="id" fit="true" queryMode="group">
   <t:dgCol title="主键"  field="id"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="结束日期"  field="endDate"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="实验室编号"  field="no"   query="true" queryMode="single"  width="100"></t:dgCol>
   <t:dgCol title="实验室名称"  field="name"   query="true" queryMode="single"  width="100"></t:dgCol> 
   <t:dgCol title="房间位置"  field="address"   query="false" queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="永久开放"  field="openFlag"   query="false" queryMode="single"  width="80" 
   			formatterjs="getBooleanVal"></t:dgCol>
   <t:dgCol title="开放时间"  field="beginDate"   query="false" queryMode="single"  width="120" 
   			formatterjs="getOpenDate"></t:dgCol>
   <t:dgCol title="开放说明"  field="openRemark" formatterjs="getRemark"   query="false" queryMode="single"  width="120"></t:dgCol> 
   			
   <t:dgCol title="操作" field="opt" width="200"></t:dgCol>
   <t:dgFunOpt title="设置永久开放" funname="setOpenFlag(id)" exp="openFlag#ne#true"/>
   <t:dgFunOpt title="取消永久开放" funname="unsetOpenFlag(id)" exp="openFlag#eq#true"/>
   <t:dgFunOpt title="设置开放时间" funname="setOpenDate(id)" />
   <t:dgFunOpt title="设置开放课程" funname="setOpenLesson(id)" />
   </t:datagrid>
  </div>
 </div>
 <script type="text/javascript">
 $(document).ready(function(){
 	//给时间控件加上样式
 });
 
 function getRemark(string){
	 string=string.replace(/\r\n/g,"<br>")    
     string=string.replace(/\n/g,"<br>");    
	 return string;
 }
 
 function setOpenLesson(id){
	 var addurl = "labOpenController.do?goSetOpenLesson&id="+id;
	 $.dialog({
			content: 'url:'+addurl,
			lock : true,
			zIndex: getzIndex(),
			width:"900px",
			height:"500px",
			title:"设置开课程",
			opacity : 0.3,
			fixed:true,
			cache:false,
		    ok: function(){
		    	//iframe = this.iframe.contentWindow;
				//saveObj();
				return true;
		    },
		    cancelVal: '关闭',
		    cancel: true /*为true等价于function(){}*/
		});
 }
 
 function getBooleanVal(v){
	 if(v == 'true'){
		 return '是';
	 }else{
		 return '否';
	 }
 }
 
 function getOpenDate(value,row,index){
	 if(row.beginDate.length == 0) return;
	 var start = row.beginDate.substring(0,10) ;
	 var end = row.endDate.substring(0,10); 
	 return start+'至'+ end;
 }
 
 
 function setOpenFlag(id){
	 $.ajax({
		url:'labOpenController.do?setOpenFlag&id='+id+"&val=1",
		success:function(data){
			data = $.parseJSON(data)
			if(data.success){
				tip(data.msg);
				reloadTable();
			}
		}
	 });
	  
 }
 
 
 function unsetOpenFlag(id){
	 $.ajax({
		url:'labOpenController.do?setOpenFlag&id='+id+"&val=0",
		success:function(data){
			data = $.parseJSON(data)
			if(data.success){
				tip(data.msg);
				reloadTable();
			}
		}
	 });
	  
 }
 
 /**
 * 设置开放时间
 */
 function setOpenDate(id){
	 var addurl = "labOpenController.do?goOpenDate&id="+id;
	 $.dialog({
			content: 'url:'+addurl,
			lock : true,
			zIndex: getzIndex(),
			width:"400px",
			height:"200px",
			title:"设置开时间",
			opacity : 0.3,
			fixed:true,
			cache:false,
		    ok: function(){
		    	iframe = this.iframe.contentWindow;
				saveObj();
				return false;
		    },
		    cancelVal: '关闭',
		    cancel: true /*为true等价于function(){}*/
		});
 }
 </script>